package cn.syy.autoconfigure;

import cn.syy.propertites.AppSettingProperties;
import cn.syy.template.AppWeChatTemplate;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnSingleCandidate;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration // 表名这是一个配置类
@EnableConfigurationProperties({AppSettingProperties.class}) // 启用配置类，配置属性文件，方便直接获取
public class WeChatAutoConfiguration {

    @Bean // 创建一个AppWeChatTemplate类型的bean对象
    @ConditionalOnMissingBean( // 避免重复的bean被定义
            name = {"appWeChatTemplate"}
    )
    public AppWeChatTemplate appWeChatTemplate(AppSettingProperties appSettingProperties) {
        AppWeChatTemplate appWeChatTemplate = new AppWeChatTemplate(appSettingProperties);
        return appWeChatTemplate;
    }
}
